﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Sockets;

namespace AlgoLogicMessenger
{
    /// <summary>
    /// Interaction logic for ManageQuizModule.xaml
    /// </summary>
    public partial class ManageQuizModule : Page
    {
        System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
        NetworkStream serverStream = default(NetworkStream);

        public ManageQuizModule()
        {
            InitializeComponent();

            //clientSocket.Connect(IP.Address, 8888);
            //serverStream = clientSocket.GetStream();
            //byte[] outStream = System.Text.Encoding.ASCII.GetBytes("" + "#");
            //serverStream.Write(outStream, 0, outStream.Length);
            //serverStream.Flush();

            //NavigationFrame.Content = null;

            //btnNavigation.Content = "Allow competitors" + Environment.NewLine + "to navigate";
        }

        private void importdatabtn_Click(object sender, RoutedEventArgs e)
        {
            ImportData im = new ImportData();
            NavigationFrame.Content = im;
        }

        private void editdatabtn_Click(object sender, RoutedEventArgs e)
        {
            byte[] outStream = System.Text.Encoding.ASCII.GetBytes("@manageQuizQuestion|#");
            if (serverStream != null)
            {
                serverStream.Write(outStream, 0, outStream.Length);
                serverStream.Flush();
            }

            ManageQuizQuestion mqq = new ManageQuizQuestion();
            NavigationFrame.Content = mqq;

        }

        string text = "";
        private void Page_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F5)
            {
                e.Handled = true;
            }
            else if (e.Key != Key.Back)
            {
                text = e.Key.ToString();
            }
            else if (e.Key == Key.Back)
            {
                if (text != "")
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = true;
                }
            }
        }

        private void btnBack_Click(object sender, RoutedEventArgs e)
        {
            NavigationService nav = NavigationService.GetNavigationService(this);
            nav.Navigate(new System.Uri("NavigationPage.xaml", UriKind.RelativeOrAbsolute));
        }
    }
}
